package com.summer.framework.core.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
import com.summer.framework.core.tenant.handler.SummerTenantLineHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Description: mybatis plus 配置
 * @auther Ice Yang
 * Date 2025/7/2
 */
@Configuration
public class MyBatisPlusConfig {

    @Autowired(required = false)
    private SummerTenantLineHandler handler;

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 多租户插件，需要在分页插件之前
        if(handler != null){
            interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(handler));
        }
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }
}
